package com.leo.train.business.controller.admin;

import com.leo.train.business.dto.DailyTrainTicketDto;
import com.leo.train.business.entity.DailyTrainTicket;
import com.leo.train.business.service.DailyTrainTicketService;
import com.leo.train.common.resp.CommonResp;
import com.leo.train.common.resp.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/admin/daily-trainTicket")
public class DailyTrainTicketAdminController {

    @Autowired
    private DailyTrainTicketService dailyTrainTicketService;

    /**
     * 新增
     * @param dailyTrainTicket
     * @return
     */
    @PostMapping("add")
    public CommonResp save(@RequestBody DailyTrainTicket dailyTrainTicket) {
        dailyTrainTicketService.save(dailyTrainTicket);
        return new CommonResp<>();
    }

    /**
     * 修改
     * @param dailyTrainTicket
     * @return
     */
    @PostMapping("/update")
    public CommonResp update(@RequestBody DailyTrainTicket dailyTrainTicket) {
        dailyTrainTicketService.save(dailyTrainTicket);
        return new CommonResp<>();
    }

    /**
     * 查询
     * @param dailyTrainTicketDto
     * @return
     */
    @GetMapping("/list")
    public CommonResp<PageResult<DailyTrainTicket>> list(DailyTrainTicketDto dailyTrainTicketDto) {
        PageResult<DailyTrainTicket> pageResult = dailyTrainTicketService.list(dailyTrainTicketDto);
        return new CommonResp<>(pageResult);
    }

    /**
     * 删除
     * @param map
     * @return
     */
    @PostMapping("/delete")
    public CommonResp delete(@RequestBody Map<String,Long> map){
        dailyTrainTicketService.delete(map.get("id"));
        return new CommonResp<>();
    }

    /**
     * 查询详情
     * @param id
     * @return
     */
    @GetMapping("/detail")
    public CommonResp<DailyTrainTicket> detail(@RequestParam Long id) {
        DailyTrainTicket dailyTrainTicket = dailyTrainTicketService.detail(id);
        return new CommonResp<>(dailyTrainTicket);
    }

}
